#-*-coding:utf-8-*-
'''
Created on 2011-1-16

@author: zhaoyh
'''
import web
from admin.config import view
from admin.models.settings import Settings
from core.meta import DBSession
class edit():
    def GET(self):
        settings=DBSession.query(Settings)
        print settings
        return view.settings_edit(s=settings)
    def POST(self):
        u=web.input()
        print u        
        try:
            for key in u:
                print u[key]
                settings=DBSession.query(Settings).filter(Settings.set_key==key).first()
                print settings
                if settings==None:
                    settings=Settings(key,u[key])
                    DBSession.add(settings)
                settings.set_value=u[key]
                DBSession.commit()
                DBSession.flush()
            return '{"statusCode":"200","message":"保存成功"}'
        except Exception,e:
            DBSession.rollback()
            print Exception,e
            return  '{"statusCode":"300", "message":"保存错误"}' 
